package com.easybuy.entity;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * EasybuyNews 实体类
 * 对应数据库表 easybuy.easybuy_news
 */
public class EasybuyNews {
    // 主键
    private Integer id;

    // 标题
    private String title;

    // 内容
    private String content;

    // 创建时间（字符串格式）
    private String createTime;

    // 无参构造函数
    public EasybuyNews() {
    }

    // 带参构造函数
    public EasybuyNews(Integer id, String title, String content, String createTime) {
        this.id = id;
        this.title = title;
        this.content = content;
        this.createTime = createTime;
    }

    // Getter 和 Setter 方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    // 便捷方法：将字符串格式的创建时间转换为LocalDate
    public LocalDate getCreateTimeAsLocalDate() {
        if (createTime != null && !createTime.trim().isEmpty()) {
            return LocalDate.parse(createTime, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        return null;
    }

    // 便捷方法：设置LocalDate格式的创建时间
    public void setCreateTimeFromLocalDate(LocalDate date) {
        if (date != null) {
            this.createTime = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        } else {
            this.createTime = null;
        }
    }

    @Override
    public String toString() {
        return "EasybuyNews{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", createTime='" + createTime + '\'' +
                '}';
    }
}